// // #include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int n;

bool conversion1(vector<string>& change, vector<string>& origin){
    // 90 度顺
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(origin[i][j] != change[j][n - 1 - i]) return false;
        }
    }
    return true;
}
bool conversion2(vector<string>& change, vector<string>& origin){
    // 180 度顺
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(origin[i][j] != change[n - 1 - i][n - 1 - j]) return false;
        }
    }
    return true;
}
bool conversion3(vector<string>& change, vector<string>& origin){
    // 270 度顺
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(origin[i][j] != change[n - 1 - j][i]) return false;
        }
    }
    return true;
}
bool conversion4(vector<string>& change, vector<string>& origin){
    // 水平翻转
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(origin[i][j] != change[i][n - 1 - j]) return false;
        }
    }
    return true;
}
bool conversion5(vector<string>& change, vector<string>& origin){
    // 水平翻转 + conversion1/2/3
    vector<string> tmp = origin;
    // 水平翻转
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            tmp[i][j] = origin[i][n - 1 - j];
        }
    }
    if(conversion1(change,tmp)){
        return true;
    }else if(conversion2(change,tmp)){
        return true;
    }else if(conversion3(change,tmp)){
        return true;
    }
    return false;
}

int main(){
    cin>>n; // 1 <= N <= 10
    vector<string> change(n);
    vector<string> origin(n);
    for(int i; i < n; ++i){
        cin >> origin[i];
    }
    for(int i; i < n; ++i){
        cin >> change[i];
    }
    int ans = 7;
    if(conversion1(change, origin)){
        ans = 1;
    }else if(conversion2(change, origin)){
        ans = 2;
    }else if(conversion3(change, origin)){
        ans = 3;
    }else if(conversion4(change, origin)){
        ans = 4;
    }else if(conversion5(change, origin)){
        ans = 5;
    }else if(origin == change){
        ans = 6;
    }
    else ans = 7;
    cout << ans << endl;
    
    return 0;
}




